package com.zqh.app.controller;

import com.alibaba.fastjson.JSON;
import com.zqh.app.entity.*;
import com.zqh.app.manager.*;
import com.zqh.common.entity.Page;
import com.zqh.common.entity.Query;
import com.zqh.common.entity.R;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(tags={"app用户接口"})
@RestController
@RequestMapping("/app/user")
public class AppUserController {

    @Autowired
    AppUserManager appUserManager;

    @Autowired
    AppGroupManager appGroupManager;

    @Autowired
    AppGroupInfoManager appGroupInfoManager;

    @Autowired
    AppMessageManager appMessageManager;

    @Autowired
    AppFeedbackManager appFeedbackManager;

    @Autowired
    AppArchivesManager appArchivesManager;

    @Autowired
    ClassifyManager classifyManager;

    @Autowired
    ArticleManager articleManager;

    @Autowired
    CommentManager commentManager;

    @Autowired
    AdManager adManager;

    @Autowired
    MerchantManager merchantManager;

    @Autowired
    WarehouseManager warehouseManager;

    @Autowired
    ChannelManager channelManager;



    /**
     * 用户列表
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "/list",method = {RequestMethod.POST})
    public Page<User> list(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<User> page = new Page<>(form);
        appUserManager.listUser(page, form);
        return page;
    }

    /**
     * 修改用户属性
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "/updateUser",method = {RequestMethod.POST})
    public R updateUser(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return appUserManager.updateUser(form);
    }

    /**
     * 创建群
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{creatorId: 1,label=\"精神病\",name:\"群\",remark=\"名字\",orgId: null}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/createGroup",method = {RequestMethod.POST})
    public R createGroup(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return appGroupManager.saveGroup(form);
    }

    /**
     * 删除群
     *
     * @param groupId
     * @return
     */
    @RequestMapping(value = "/delGroup",method = {RequestMethod.POST} )
    public R delGroup(String groupId) {
        return appGroupManager.delGroup(groupId);
    }

    /**
     * 修改群
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{groupId: '档案ID', title: '标题',content:'病例内容'}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/updateGroup",method = {RequestMethod.POST} )
    public R updateGroup(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return appGroupManager.updateGroup(form);
    }

    /**
     * 获取群列表
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{sortOrder: \"asc\", pageSize: 10, pageNumber: 1, orgId: null}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/getGroups",method = {RequestMethod.POST})
    public Page<Group> getGroups(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<Group> page = new Page<>(form);
        appGroupManager.getGroups(page, form);
        return page;
    }

    /**
     * 添加成员
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：[{creatorId: 1,memberId:1,groupId:1,nicename: \"哈哈\"}]",dataType = "string",paramType = "body")
    @RequestMapping(value = "/addMembers",method = {RequestMethod.POST} )
    public R addMembers(String params) {
        List<GroupInfo> map = JSON.parseArray(params, GroupInfo.class);
        return appGroupInfoManager.addMembers(map);
    }

    /**
     * 删除成员
     *
     * @param groupInfoId
     * @return
     */
    @RequestMapping(value = "/delMember",method = {RequestMethod.POST})
    public R delMembers(int groupInfoId) {
        return appGroupInfoManager.delMember(groupInfoId);
    }

    /**
     * 获取群成员列表
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{sortOrder: \"asc\", pageSize: 10, pageNumber: 1, groupId: 1}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/getGroupUsers",method = {RequestMethod.POST} )
    public Page<GroupInfo> getGroupUsers(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<GroupInfo> page = new Page<>(form);
        appGroupInfoManager.getGroupUsers(page, form);
        return page;
    }

    /**
     * 获取最近用户消息
     *
     * @param params
     * @return
     */

    @ApiImplicitParam(name = "params",value = " 例子：{sortOrder: \"asc\", pageSize: 10, pageNumber: 1, askUserId: 66}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/getUserMessages",method = {RequestMethod.POST})
    public Page<Message> getUserMessages(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<Message> page = new Page<>(form);
        appMessageManager.listMessage1(page, form);
        return page;
    }

    /**
     * 获取留言
     *
     * @param params
     * @return
     */

    @ApiImplicitParam(name = "params",value = " 例子：{sortOrder: \"asc\", pageSize: 10, pageNumber: 1, askUserId: 66}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/getMessages",method = {RequestMethod.POST})
    public Page<Message> getMessages(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<Message> page = new Page<>(form);
        appMessageManager.listMessage(page, form);
        return page;
    }

    /**
     * 发送留言
     *
     * @param params
     * @return
     */

    @ApiImplicitParam(name = "params",value = " 例子：{\"askUserId\": 1276,\"acceptUserId\":1,\"content\": \"ok\"}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/sendMessage",method = {RequestMethod.POST} )
    public R sendMessage(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return appMessageManager.sendMessage(form);
    }

    /**
     * 获取意见反馈列表
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{sortOrder: \"asc\", pageSize: 10, pageNumber: 1}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/getFeedbackList",method = {RequestMethod.POST} )
    public Page<Feedback> getFeedbackList(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<Feedback> page = new Page<>(form);
        appFeedbackManager.getFeedbackList(page, form);
        return page;
    }

    /**
     * 修改反馈信息
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{feedbackId:35, sign: \"processed\",receiver:\"huo\"}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/updateFeedbackInfo",method = {RequestMethod.POST} )
    public R updateFeedbackInfo(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return appFeedbackManager.updateFeedbackInfo(form);
    }

    /**
     * 添加档案
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{userId: '用户id', creatorId: '当前登陆管理员ID', title: '标题',content:'病例内容',orgId:1}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/addArchives",method = {RequestMethod.POST} )
    public R addArchives(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return appArchivesManager.addArchives(form);
    }

    /**
     * 修改档案
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{archivesId: '档案ID', title: '标题',content:'病例内容'}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/updateArchives",method = {RequestMethod.POST} )
    public R updateArchives(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return appArchivesManager.updateArchives(form);
    }

    /**
     * 删除档案
     *
     * @param archivesId
     * @return
     */
    @RequestMapping(value = "/delArchives",method = {RequestMethod.POST} )
    public R delArchives(int archivesId) {
        return appArchivesManager.delArchives(archivesId);
    }


    /**
     * 获取档案列表
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{sortOrder: \"asc\", pageSize: 10, pageNumber:1,orgId:1}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/getArchives",method = {RequestMethod.POST})
    public Page<Archives> getArchives(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<Archives> page = new Page<>(form);
        appArchivesManager.getArchives(page, form);
        return page;
    }

    /**
     * 获取融云Token
     *
     * @param userId
     * @return
     */
    @RequestMapping(value = "/getRongToken",method = {RequestMethod.GET} )
    public R getRongToken(Integer userId) {

        return appMessageManager.getRongToken(userId);
    }

    /**
     * 获取融云Token
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/getCustomer",method = {RequestMethod.POST} )
    public List<Customer> getCustomer() {

        return appMessageManager.listMessage2();
    }

    @RequestMapping(value = "/saveCustomer",method = {RequestMethod.POST} )
    public R saveCustomer(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return appMessageManager.saveys(form);
    }

    /**
     * 删除客服医师
     *
     * @param customerServiceId
     * @return
     */
    @RequestMapping(value = "/delCustomer",method = {RequestMethod.POST} )
    public R delCustomer(int customerServiceId) {
        return appMessageManager.delCustomer(customerServiceId);
    }

    /**
     * 获取分类列表
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{sortOrder: \"asc\", pageSize: 10, pageNumber:1}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/getClassifys",method = {RequestMethod.POST})
    public Page<SungoClassify> getSungoClassifys(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<SungoClassify> page = new Page<>(form);
        classifyManager.getSungoClassifyList(page, form);
        return page;
    }

    /**
     * 删除分类
     *
     * @param classifyId
     * @return
     */
    @RequestMapping(value = "/delClassifys",method = {RequestMethod.POST} )
    public R delClassifys(int classifyId) {
        return classifyManager.delClassifys(classifyId);
    }

    /**
     * 添加分类
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{userId: '用户id', creatorId: '当前登陆管理员ID', title: '标题',content:'病例内容',orgId:1}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/addClassifys",method = {RequestMethod.POST} )
    public R addClassifys(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return classifyManager.addClassifys(form);
    }

    /**
     * 修改分类
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{archivesId: '档案ID', title: '标题',content:'病例内容'}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/updateClassifys",method = {RequestMethod.POST} )
    public R updateClassifys(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return classifyManager.updateClassifys(form);
    }

    /**
     * 获取文章列表
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{sortOrder: \"asc\", pageSize: 10, pageNumber:1}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/getArticles",method = {RequestMethod.POST})
    public Page<SungoArticle> getArticles(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<SungoArticle> page = new Page<>(form);
        articleManager.getArticles(page, form);
        return page;
    }

    /**
     * 删除文章
     *
     * @param articleId
     * @return
     */
    @RequestMapping(value = "/delArticles",method = {RequestMethod.POST} )
    public R delArticles(int articleId) {
        return articleManager.delArticles(articleId);
    }

    /**
     * 添加文章
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{userId: '用户id', creatorId: '当前登陆管理员ID', title: '标题',content:'病例内容',orgId:1}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/addArticles",method = {RequestMethod.POST} )
    public R addArticles(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return articleManager.addArticles(form);
    }

    /**
     * 修改分类
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{archivesId: '档案ID', title: '标题',content:'病例内容'}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/updateArticles",method = {RequestMethod.POST} )
    public R updateArticles(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return articleManager.updateArticles(form);
    }

    /**
     * 获取评论列表
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{sortOrder: \"asc\", pageSize: 10, pageNumber:1}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/getComments",method = {RequestMethod.POST})
    public Page<SungoComment> getComments(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<SungoComment> page = new Page<>(form);
        commentManager.getComments(page, form);
        return page;
    }

    /**
     * 审核评论
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{commentId: 1, show:1}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/reviewComments",method = {RequestMethod.POST})
    public R reviewComments(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return commentManager.reviewComments(form);
    }


    /**
     * 获取广告列表
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{sortOrder: \"asc\", pageSize: 10, pageNumber:1}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/getAds",method = {RequestMethod.POST})
    public Page<SungoAd> getAds(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<SungoAd> page = new Page<>(form);
        adManager.getAds(page, form);
        return page;
    }

    /**
     * 删除广告
     *
     * @param adId
     * @return
     */
    @RequestMapping(value = "/delAd",method = {RequestMethod.POST} )
    public R delAd(int adId) {
        return adManager.delAd(adId);
    }

    /**
     * 添加广告
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{userId: '用户id', creatorId: '当前登陆管理员ID', title: '标题',content:'病例内容',orgId:1}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/addAd",method = {RequestMethod.POST} )
    public R addAd(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return adManager.addAd(form);
    }

    /**
     * 修改广告
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{archivesId: '档案ID', title: '标题',content:'病例内容'}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/updateAd",method = {RequestMethod.POST} )
    public R updateAd(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return adManager.updateAd(form);
    }

    /**
     * 获取厂家
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/getMerchant",method = {RequestMethod.POST} )
    public List<SysMerchant> getMerchant() {
        return merchantManager.listMerchant();
    }

    /**
     * 入库
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/addWarehouse",method = {RequestMethod.POST} )
    public R addWarehouse(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return warehouseManager.addWarehouse(form);
    }

    /**
     * 返回库存
     *
     * @param
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{sortOrder: \"asc\", pageSize: 10, pageNumber:1}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/getWarehouse",method = {RequestMethod.POST} )
    public Page<SysWarehouse> getWarehouse(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        Page<SysWarehouse> page = new Page<>(form);
        warehouseManager.getWarehouse(page, form);
        return page;
    }

    /**
     * 修改库存
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{archivesId: '档案ID', title: '标题',content:'病例内容'}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/upWarehouse",method = {RequestMethod.POST} )
    public R upWarehouse(String params) {
        Map map = JSON.parseObject(params);
        Query form = new Query(map);
        return warehouseManager.upWarehouse(form);
    }

    /**
     * 修改库存
     *
     * @param params
     * @return
     */
    @ApiImplicitParam(name = "params",value = " 例子：{archivesId: '档案ID', title: '标题',content:'病例内容'}",dataType = "string",paramType = "body")
    @RequestMapping(value = "/upWarehouses",method = {RequestMethod.POST} )
    public R upWarehouses(String params) {
        List<SysWarehouse> map = JSON.parseArray(params, SysWarehouse.class);
        return warehouseManager.upWarehouses(map);
    }

    /**
     * 获取销售渠道
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/getChannel",method = {RequestMethod.POST} )
    public List<SysChannel> getChannel() {
        return channelManager.getChannel();
    }
}